package com.binarytree;

import java.util.LinkedList;

public class Solution16 {

    public int findBottomLeftValue(TreeNode root) {
        LinkedList<TreeNode> queue = new LinkedList<>();
        int res = 0;
        queue.add(root);
        while (!queue.isEmpty()) {
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                TreeNode treeNode = queue.removeFirst();
                if (i == 0) {
                    res = treeNode.val;
                }
                if (treeNode.left!= null) queue.add(treeNode.left);
                if (treeNode.right!=null) queue.add(treeNode.right);
            }
        }
        return res;
    }
}
